package TreeSeries;

import java.util.ArrayList;
import java.util.List;

public class LevelOrderByRecursionSolution_102 {
    public List<List<Integer>> result = new ArrayList<List<Integer>>();

    public List<List<Integer>> levelOrder(TreeNode root) {


        levelOrderRecursion(root, 0);

        return result;
    }

    public void levelOrderRecursion(TreeNode node, Integer deep) {
        if (node == null) return;
        deep++;

        if (result.size() < deep) {
            List<Integer> res = new ArrayList<>();
            result.add(res);
        }
        result.get(deep - 1).add(node.val);

        levelOrderRecursion(node.left, deep);
        levelOrderRecursion(node.right, deep);
    }
}
